package com.woniu.crowd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.crowd.infra.model.SelectLog;
import com.woniu.crowd.infra.model.SelectProduct;
import com.woniu.crowd.infra.model.UserOpinion;
import com.woniu.crowd.infra.mapper.UserOpinionMapper;
import com.woniu.crowd.service.SelectLogService;
import com.woniu.crowd.service.SelectProductService;
import com.woniu.crowd.service.UserOpinionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.crowd.service.form.AddUserOpinionForm;
import com.woniu.exception.LXLGException;
import com.woniu.product.client.ProductQueryClient;
import com.woniu.product.client.result.SpuResultInfo;
import com.woniu.result.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户甄选意见表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2022-11-26
 */
@Service
public class UserOpinionServiceImpl extends ServiceImpl<UserOpinionMapper, UserOpinion> implements UserOpinionService {
    @Resource
    private ProductQueryClient productQueryClient;
    @Resource
    private SelectLogService selectLogService;

    @Resource
    private SelectProductService selectProductService;
    @Override
    public void AdduserAddOpinion(AddUserOpinionForm addUserOpinionForm) {


        SelectProduct byId = selectProductService.getById(addUserOpinionForm.getSelectId());
        if (byId == null) {
            throw new LXLGException("甄选信息不存在", 500);
        }
        UserOpinion userOpinion = BeanUtil.copyProperties(addUserOpinionForm, UserOpinion.class);
        save(userOpinion);
        SelectLog log = selectLogService.getOne(new QueryWrapper<SelectLog>().eq("select_product_id", addUserOpinionForm.getSelectId()));
        log.setTestId(userOpinion.getUserOpinionId());
        selectLogService.updateById(log);
    }
}
